<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="__ROOT__/static/admin/css/pintuer.css">
    <link rel="stylesheet" href="__ROOT__/static/admin/css/admin.css">
    <script src="__ROOT__/static/admin/js/jquery.js"></script>
    <script src="__ROOT__/static/admin/js/pintuer.js"></script>
    <script src="__ROOT__/static/plugins/layer/layer.min.js"></script>
    <script>

        // 设置首页
        function setHome(){
            var html = [];
            $(".checkid").each(function(){
                if($(this).prop('checked'))html.push($(this).val());
            });
            var res = html.join(",");
            var params = {};
            params.id = res;
            console.dir(params.id);
            layer.confirm('确认设置首页吗?',function(){
                $.post("{:url('admin/Knows/setHome')}",params,function(data){
                    if(data==1) {
                        layer.msg('设置首页成功', {icon:1});
                        setTimeout('location.href="{:url(\'admin/Knows/index\')}"',2500);
                    }else{
                        layer.msg('设置首页失败', {icon: 2});
                    }
                })
            });
        }

        // 取消首页
        function cancelHome(){
            var html = [];
            $(".checkid").each(function(){
                if($(this).prop('checked'))html.push($(this).val());
            });
            var res = html.join(",");
            var params = {};
            params.id = res;
            layer.confirm('确认取消首页吗?',function(){
                $.post("{:url('admin/Knows/cancelHome')}",params,function(data){
                    if(data==1) {
                        layer.msg('取消首页成功', {icon: 1});
                        setTimeout('location.href="{:url(\'admin/Knows/index\')}"',2500);
                    }else{
                        layer.msg('取消首页失败', {icon: 1});
                        window.location.href = "{:url('admin/Knows/index')}";
                    }
                })
            });
        }

        // 设置推荐
        function setRecom(){
            var html = [];
            $(".checkid").each(function(){
                if($(this).prop('checked'))html.push($(this).val());
            });
            var res = html.join(",");
            var params = {};
            params.id = res;
            layer.confirm('确认设置推荐吗?',function(){
                $.post("{:url('admin/Knows/setRecom')}",params,function(data){
                    if(data==1) {
                        layer.msg('设置推荐成功', {icon: 1});
                        setTimeout('location.href="{:url(\'admin/Knows/index\')}"',2500);;
                    }else{
                        layer.msg('设置推荐失败', {icon: 1});
                        window.location.href = "{:url('admin/Knows/index')}";
                    }
                })
            });
        }

        // 取消推荐
        function cancelRecom(){
            var html = [];
            $(".checkid").each(function(){
                if($(this).prop('checked'))html.push($(this).val());
            });
            var res = html.join(",");
            var params = {};
            params.id = res;
            layer.confirm('确认取消推荐吗?',function(){
                $.post("{:url('admin/Knows/cancelRecom')}",params,function(data){
                    if(data==1) {
                        layer.msg('取消推荐成功', {icon: 1});
                        setTimeout('location.href="{:url(\'admin/Knows/index\')}"',2500);
                    }else{
                        layer.msg('取消推荐失败', {icon: 1});
                        window.location.href = "{:url('admin/Knows/index')}";
                    }
                })
            });
        }

        //  设置置顶
        function setTop(){
            var html = [];
            $(".checkid").each(function(){
                if($(this).prop('checked'))html.push($(this).val());
            });
            var res = html.join(",");
            var params = {};
            params.id = res;
            layer.confirm('确认设置置顶吗?',function(){
                $.post("{:url('admin/Knows/setTop')}",params,function(data){
                    if(data==1) {
                        layer.msg('设置置顶成功', {icon: 1});
                        setTimeout('location.href="{:url(\'admin/Knows/index\')}"',2500);
                    }else{
                        layer.msg('设置置顶失败', {icon: 1});
                        window.location.href = "{:url('admin/Knows/index')}";
                    }
                })
            });
        }

        // 取消置顶
        function cancelTop(){
            var html = [];
            $(".checkid").each(function(){
                if($(this).prop('checked'))html.push($(this).val());
            });
            var res = html.join(",");
            var params = {};
            params.id = res;
            layer.confirm('确认取消置顶吗?',function(){
                $.post("{:url('admin/Knows/cancelTop')}",params,function(data){
                    if(data==1) {
                        layer.msg('取消置顶成功', {icon: 1});
                        setTimeout('location.href="{:url(\'admin/Knows/index\')}"',2500);
                    }else{
                        layer.msg('取消置顶失败', {icon: 1});
                        window.location.href = "{:url('admin/Knows/index')}";
                    }
                })
            });
        }
    </script>
</head>
<body>
<div id="listform">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder"> 内容列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
        <form method="post" action="{:url('admin/Knows/index')}">
            <div class="padding border-bottom">
                <ul class="search" style="padding-left:10px;">
                    <li> <a class="button border-main icon-plus-square-o" href="{:url('admin/Knows/addKnowsView')}"> 添加内容</a> </li>
                    <li>搜索：</li>
                    <li>首页
                        <select name="s_ishome" id="s_ishome" class="input" style="width:60px; line-height:17px; display:inline-block">
                            <option value="0">选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                        &nbsp;&nbsp;
                        推荐
                        <select name="s_isvouch" id="s_isvouch" class="input" style="width:60px; line-height:17px;display:inline-block">
                            <option value="0">选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                        &nbsp;&nbsp;
                        置顶
                        <select name="s_istop" id="s_istop" class="input" style="width:60px; line-height:17px;display:inline-block">
                            <option value="0" >选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </li>
                    <li>
                        <input type="text" placeholder="请输入搜索关键字" id="parenting_title" name="parenting_title" class="input" style="width:250px; line-height:17px;display:inline-block" value="" />
                        <input type="submit" class="button border-main icon-search" value="搜索"/>
                    </li>
                </ul>
            </div>
        </form>
        <table class="table table-hover text-center">
            <tr>
                <th width="100" style="text-align:left; padding-left:20px;">ID</th>
                <th>图片</th>
                <th>名称</th>
                <th>属性</th>
                <th>分类名称</th>
                <th width="10%">更新时间</th>
                <th width="310">操作</th>
            </tr>
            {volist name="res" id="vo"}
            <tr>
                <td style="text-align:left; padding-left:20px;"><input type="checkbox"  class="checkid"  name="id" value="{$vo.id}" />
                    {$vo.id}
                </td>
                <td width="10%"><img src="__ROOT__{$vo.album_url}" alt="" width="70" height="50" /></td>
                <td>{$vo.parenting_title}</td>
                <td>
                    {if condition="$vo.is_home"==1}<span class='label label-success'>首页</span>{/if}
                    {if condition="$vo.is_vouch"==1}<span class='label label-success'>推荐</span>{/if}
                    {if condition="$vo.is_top"==1}<span class='label label-success'>置顶</span>{/if}
                </td>
                <td>{$vo.know_name}</td>
                <td>{:date('Y-m-d H:i:s',$vo.knows_time)}</td>
                <td>
                    <div class="button-group">
                        <a class="button border-main" href="{:url('admin/Knows/updateKnowsView',array('id'=>$vo['id']))}"><span class="icon-edit"></span> 修改</a>
                        <a class="button border-red" href="javascript:void(0)" onclick="del({$vo.id})"><span class="icon-trash-o"></span> 删除</a>
                    </div>
                </td>
            </tr>
            {/volist}
            <tr>
                <td style="text-align:left; padding:19px 0;padding-left:20px;"><input type="checkbox" id="checkall"/>
                    全选 </td>
                <td colspan="7" style="text-align:left;padding-left:20px;">
                    <button type="button"class="button border-red icon-trash-o" onclick="DelSelect()"> 批量删除</button>
                    <button type="button" class="button border-main icon-plus-square-o" onclick='javascript:setHome()'>设置首页</button>
                    <button type="button" class="button border-red " onclick='javascript:cancelHome()'>取消首页</button>
                    <button type="button" class="button border-main icon-plus-square-o" onclick='javascript:setRecom()'>设置推荐</button>
                    <button type="button" class="button border-red " onclick='javascript:cancelRecom()'>取消推荐</button>
                    <button type="button" class="button border-main icon-plus-square-o" onclick='javascript:setTop()'>设置置顶</button>
                    <button type="button" class="button border-red " onclick='javascript:cancelTop'>取消置顶</button>
            </tr>
            <tr>
                <td colspan="8">
                    <div class="pagelist">
                        {$page}
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<script type="text/javascript">
    //单个删除
    function del(id){
        var knows = {};
        knows.id = id;
        layer.confirm('您确定要删除吗?', {
            btn: ['确定','取消']
        },  function(){
            $.post("{:url('admin/Knows/delKnows')}", knows, function (response){
                if(response > 0){
                    layer.msg('删除成功', {icon: 5});
                    window.location.href = "{:url('admin/Knows/index')}";
                }else {
                    layer.msg('删除失败', {icon: 5});
                }

            });
        });

    }

    //全选
    $("#checkall").click(function(){
        $("input[name='id']").each(function(){
            if (this.checked) {
                this.checked = false;
            }
            else {
                this.checked = true;
            }
        });
    })

    //批量删除
    function DelSelect(){
        var obj = $('input[class="checkid"]:checked');
        var html=[];
        $(obj).each(function(){
            html.push($(this).val()) ;
        });
        var html2 = html.join(',');
        var parmas={};
        parmas.ids=html2;
        layer.confirm('您确定要删除吗?', {
            btn: ['确定','取消']
        },  function() {
            $.post("{:url('admin/Knows/deleteBatch')}", parmas, function (response) {
                if (response[0] == 1) {
                    layer.msg('删除成功', {icon: 5});
                    window.location.href = "{:url('admin/Knows/index')}";
                } else {
                    layer.msg('删除失败', {icon: 5});
                }
            });
        });
    }



</script>
</body>
</html>